import { PageList } from "@/api/menu";
import { listToTree } from "@/utils/tree";

export default {
  props: {
    treeType: {
      type: String,
      default: ""
    }
  },
  methods: {
    CheckTreeData() {
      switch (this.treeType) {
        case "menu":
          this.LoadMenuTree();
          break;
      }
    },

    // 加载 菜单树
    LoadMenuTree() {
      const postData = {
        "page.current": 1,
        "page.size": 1000,
        menuType: 1
      };
      PageList(postData)
        .then(response => {
          if (response.code === 200) {
            const { data } = response;
            const { records } = data;
            const childrenNav = [];
            listToTree(records, childrenNav, 0, {
              key: "id",
              title: "menuName"
            });
            this.treeData = childrenNav;
            console.log("获取菜单列表_treeData", this.treeData);
            this.generateList(childrenNav);
            console.log("获取菜单列表_dataList", this.dataList);
          }
        })
        .catch(error => {});
    }
  }
};
